<template>
  <div class="el-dialog-div" ref="formBox">
    <el-form ref="form" :model="form" label-width="120px">
      <el-form-item label="入账操作" prop="mutualAccount">
        <el-radio v-model="radio" label="1">入金</el-radio>
        <el-radio v-model="radio" label="2">退款:只做标识,不做真实退款</el-radio>
      </el-form-item>
      <el-form-item v-if="radio==1" label="入账关键字" prop="search">
        <el-input v-model="queryParams.search" placeholder="姓名、UID、电话号码" clearable style="width: 230px" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <div class="table-box" v-if="radio==1">

        <el-table height="250px" :data="userList" stripe border>
          <el-table-column label="序号" type="index" width="60" align="center" />
          <el-table-column label="姓名" prop="name" width="150" align="center" />
          <el-table-column label="UID" prop="id" width="130" align="center" />
          <el-table-column label="电话号码" prop="phone" width="180" align="center" />
          <el-table-column label="操作" align="center" fixed="right" width="150">
            <template slot-scope="scope">
              <el-button size="mini" type="text" @click="selectUser(scope.row)">选择</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="totalNum > 0" :total="totalNum" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getScreenUserList" />

      </div>

    </el-form>
  </div>
</template>

<script>
import { screenUser } from "@/api/system/user";

export default {
  name: 'formView',
  props: {
    form: {
      type: Object,
    },
  },
  watch: {
    "queryParams": {
      deep: true,
      handler: function (newV, oldV) {
        this.getScreenUserList();
      },
    },
    radio(newV, oldV) {
      this.id = undefined;
      this.params.radio = this.radio;
      if (newV == 2) {
        this.params.userId = undefined;
      } else {
        this.getScreenUserList();
      }
    }
  },

  data() {
    return {
      search: '',
      radio: 0,
      params: {
        id: undefined,
        userId: undefined,
        radio: undefined
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        search: undefined
      },
      userList: [],
      totalNum: 0
    }
  },

  mounted() {
    this.reset();
    // this.getScreenUserList();
  },

  methods: {
    reset() {
      this.params = {};
      this.queryParams.search = undefined;
      this.queryParams.pageNum = 1;
    },
    selectUser(data) {
      this.params.userId = data.id;
      this.params.name = data.name;
      this.queryParams.search = data.id;
      this.params.id = this.form.id;
      this.params.radio = this.radio;
    },
    getScreenUserList() {
      screenUser(this.queryParams).then((response) => {
        if (response.code == 200) {
          this.userList = response.data;
          this.totalNum = response.total;
        }
      });
    },
  }
}
</script>

<style lang="scss" scoped>
.el-dialog-div {
  height: 70vh;
  overflow: auto;
  padding-right: 30px;
}
.table-box {
  margin-left: 40px;
}
</style>
